很多数据库工具只能导出到csv且是utf8编码,excel找开大概率会乱码
所以借Dropzone4 写了下个转换工具

  • Dropzone是MAC系统下的一个效率工具,默认带一些国内不怎么好用的Action,不确定windos有没有类似工具
  • Dropzone4 还是很好用的,直接拖文件到任务栏图标,或在文件上点击右键菜单选RunDropzoneAction然后选自己写的Action即可
  • csvToXlsx 是在相同目录下生成相同文件的xlsx,核心是pands转换的,没啥难度,尾部有操作截图
  • 先上代码
# Dropzone Action Info
# Name: csvToXlsx
# Description: convert csv to excel xlsx
# Handles: Files, Text
# Creator: spx
# URL: https://yoursite.com
# Events: Clicked, Dragged
# KeyModifiers: Command, Option, Control, Shift
# SkipConfig: No
# RunsSandboxed: No
# Version: 1.0
# MinDropzoneVersion: 4.0
# PythonPath: /usr/local/bin/python3
# PythonPath很重要,不然调用的Dropzone4带的python不是系统的
# pip install pandas;

import time
import os
import pandas as pd


def csv_to_xlsx_pd(file_path):
    csv = pd.read_csv(file_path, encoding='utf-8')
    dz.percent(50)
    base, ext = os.path.splitext(file_path)
    result_file_path = base + ".xlsx"
    dz.text("result_file_path:" + result_file_path)
    csv.to_excel(result_file_path, sheet_name='sheet1',index=False)
    dz.percent(90)

def dragged():
    print(items)
    if not items:
        dz.text("must be a csv file")
        dz.finish("Task error")
        return
    file_path = items[0]
    base, ext = os.path.splitext(file_path)
    print("base:"+ base + ",ext:"+ ext)
    if ext!=".csv":
        dz.text("must be a csv file")
        dz.finish("Task error")
        return
    
    
    dz.begin("Starting")
    dz.determinate(True)

    dz.percent(10)
    time.sleep(1)
    csv_to_xlsx_pd(file_path)
    time.sleep(1)
    dz.percent(100)

    dz.finish("Task Complete")

 
def clicked():
    import sys
    dz.alert("csv to excel","drag any csv file to convert")
    dz.finish("You clicked me!")
    dz.url(False)

a1567a9fef83d3a5bdfa11bab9898dbf.png
ba53536a3d916036bb0b34b36a60d4f3.png